package com.excellent.CourseUtils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ReadTxtFile {
    public static void main(String[] args) {
        String filePath = "C:\\专业实习-周五\\professional-internship-1\\excellent\\src\\main\\java\\com\\sanda\\excellent\\CourseUtils\\name.txt"; // 替换为你的txt文件路径
        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            int lineCount = 0;
            StringBuilder oddLines = new StringBuilder();
            StringBuilder evenLines = new StringBuilder();

            while ((line = reader.readLine()) != null) {
                lineCount++;
                if (lineCount % 2 == 0) {
                    evenLines.append(line).append("\n");
                } else {
                    oddLines.append(line).append("\n");
                }
            }

            System.out.println("单数行内容：");
            System.out.println(oddLines.toString());
            System.out.println("双数行内容：");
            System.out.println(evenLines.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
